package logic

import (
	"context"
	"doctor-medicine-system/models/mysql"
	"errors"

	"doctor-medicine-system/doctorrpc/doctorrpc"
	"doctor-medicine-system/doctorrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DoctorShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDoctorShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoctorShowLogic {
	return &DoctorShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DoctorShowLogic) DoctorShow(in *doctorrpc.DoctorShowRequest) (*doctorrpc.DoctorShowResponse, error) {
	// todo: add your logic here and delete this line
	var doctor mysql.Doctor
	err := doctor.DoctorShow(mysql.DB, in.DoctorId)
	if err != nil {
		return nil, err
	}
	if doctor.ID == 0 {
		return nil, errors.New("用户不存在")
	}
	return &doctorrpc.DoctorShowResponse{
		DoctorCode: doctor.DoctorCode,
		Password:   doctor.Password,
		Node:       doctor.Node,
	}, nil
}
